package commands
{
	import bussines.LoginDelegate;
	
	import com.adobe.cairngorm.commands.Command;
	import com.adobe.cairngorm.control.CairngormEvent;
	
	import events.LoginEvent;
	
	import model.LoginModel;
	import model.ProjectModelLocator;
	
	import mx.rpc.IResponder;
	
	import vo.User;

	public class LoginCommand implements Command, IResponder
	{
		private var evt:LoginEvent;

		public function execute(event:CairngormEvent):void
		{
			evt = event as LoginEvent;
			var delegate:LoginDelegate = new LoginDelegate(this);
			var user:User = new User();
			user.username = evt.username;
			delegate.login(user);
		}
		
		public function result(data:Object):void
		{
			trace(data.result);
			var loginModel:LoginModel = ProjectModelLocator.instance.loginModel;
			loginModel.user = data.result;
		}
		
		public function fault(info:Object):void
		{
			trace("Error: "+info);
		}
		
	}
}